local hx__ruoyu = fk.CreateSkill{
  name = "hx__ruoyu",
  tags = { Skill.Lord },
}

hx__ruoyu:addEffect("active", {
  name = "hx__ruoyu",
  anim_type = "big",
  prompt = "#hx__ruoyu",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedEffectTimes(hx__ruoyu.name, Player.HistoryGame) == 0 and
      table.find(Fk:currentRoom().alive_players, function(p)
        return p ~= player and p.kingdom == "shu"
      end)
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= player and to_select.kingdom == "shu"
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local to = effect.tos[1]
    room:recover {
      who = to,
      num = to.maxHp - to.hp,
      recoverBy = player,
      skillName = hx__ruoyu.name,
    }
    local num = math.max(to.maxHp - to:getHandcardNum(), 0)
    to:drawCards(num, hx__ruoyu.name)
  end,
})

hx__ruoyu:addEffect(fk.EventPhaseStart, {
  can_trigger = function(self, event, target, player)
    return target == player and player:hasSkill(hx__ruoyu.name) and player.phase == Player.Play and
      player:hasSkill("hx__xiangle", true) and table.find(player.room.alive_players, function(p)
        return p.kingdom == "shu" and p ~= player 
      end) and player:getMark("@hx__xiangle_yu") < 10
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player)
    local room = player.room
    local Num = #table.filter(room.alive_players, function(p)
      return p.kingdom == "shu" and p ~= player
    end)
    room:addPlayerMark(player, "@hx__xiangle_yu", math.min(Num * 2, 10 - player:getMark("@hx__xiangle_yu")))
  end,
})

return hx__ruoyu
